/*****************************************************************************
* File Name: trackpad.h
*
* Version: 1.0
*
* Description:
* This file contains functions and macros for trackpad module 
*
* Note:
* Define DISABLE_TRACKPAD in platform.h to disable trackpad module
*
* Owner: SKUV
*
* Related Document:
* CapSense Gesture data sheet
*
* Hardware Dependency:
* Trackpad PCB
*
* Code Tested With:
* 1. PSoC Creator 3.1 
* 2. ARM GCC 4.8.4
******************************************************************************
* Copyright (2015), Cypress Semiconductor Corporation.
******************************************************************************
* This software is owned by Cypress Semiconductor Corporation (Cypress) and is
* protected by and subject to worldwide patent protection (United States and
* foreign), United States copyright laws and international treaty provisions.
* Cypress hereby grants to licensee a personal, non-exclusive, non-transferable
* license to copy, use, modify, create derivative works of, and compile the
* Cypress Source Code and derivative works for the sole purpose of creating
* custom software in support of licensee product to be used only in conjunction
* with a Cypress integrated circuit as specified in the applicable agreement.
* Any reproduction, modification, translation, compilation, or representation of
* this software except as specified above is prohibited without the express
* written permission of Cypress.
*
* Disclaimer: CYPRESS MAKES NO WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, WITH
* REGARD TO THIS MATERIAL, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 
* Cypress reserves the right to make changes without further notice to the
* materials described herein. Cypress does not assume any liability arising out
* of the application or use of any product or circuit described herein. Cypress
* does not authorize its products for use as critical components in life-support
* systems where a malfunction or failure may reasonably be expected to result in
* significant injury to the user. The inclusion of Cypress' product in a life-
* support systems application implies that the manufacturer assumes all risk of
* such use and in doing so indemnifies Cypress against all charges. Use may be
* limited by and subject to the applicable Cypress software license agreement.
*****************************************************************************/
#ifndef _TRACKPAD_H_
#define _TRACKPAD_H_

#include "platform.h"
#include "device.h"

#define SCROLLUP                            (0x01) /*Increment the zwheel is incremented by 1 */
#define SCROLLDOWN                          (0xff) /*Decrement the zwheel is incremented by 1 */
#define SCROLLRIGHT                         (0x01) /*Increment the hwheel is incremented by 1 */
#define SCROLLLEFT                          (0xFF) /*Decrement the hwheel is incremented by 1 */

#define LEFTCLICK                           (0x01) /*Left click is defined as the 5th bit by the dongle */
#define RIGHTCLICK                          (0x02) /*Right click is defined as the 6th bit by the dongle */ 
#define MIDDLECLICK                         (0x04) /*Middle click is defined as the 7th bit by the dongle */ 
  
/*Keyboard Shortcuts */
#define CTRL_KEY                            (0x01) /*Control Key */
#define ALT_KEY                             (0x04) /*ALT Key */
#define WINDOWS_KEY                         (0x08) /*Windows Key */

#define C_KEY                               (0x06) /*C key*/
#define M_KEY                               (0x10) /*M key*/
#define Z_KEY                               (0x1D) /*Z key*/
#define BACKSPACE_KEY                       (0x2A) /*Backspace key*/

#define INVALID_FINGERS_DETECTED            (0xFFFFFFFF)
#define ZERO_FINGER_DETECTED                (0x0)
#define ONE_FINGER_DETECTED                 (0x1)
#define TWO_FINGER_DETECTED                 (0x2)
    
#ifdef TRACKPAD_TEMPERATURE_VARIATION
/* macro to define signal threshold for temperature variation */
#define TRACKPAD_TEMPERATURE_THRESHOLD      (0x28)
/* macro to define threshold for sensor count in case of temperature variation */
#define TRACKPAD_TEMPERATURE_SENSORCOUNT    (12)
#endif /* TRACKPAD_TEMPERATURE_VARIATION */

#ifndef DISABLE_TRACKPAD
/*****************************************************************************
* Function Name: Trackpad_Init()
******************************************************************************
* Summary:
* This functions is used to initialize Trackpad module.
*
* Parameters:
* None
*
* Return:
* None
*
* Theory:
* 
*
* Side Effects:
* 
*
*****************************************************************************/
extern void Trackpad_Init(void);

/*****************************************************************************
* Function Name: Trackpad_Start_Poll()
******************************************************************************
* Summary:
* This functions is used to initiate trackpad scanning.
*
* Parameters:
* None
*
* Return:
* None
*
* Theory:
* This function starts scans for all enabled widgets
*
* Side Effects:
* 
*
* NOTE:  Sequence of functions to be called by application for successful Trackpad Module scanning and 
*        gesture decoding is as follows
*        1) Trackpad_Start_Poll()
*        2) Trackpad_IsComplete()
*        3) Trackpad_Poll()
*****************************************************************************/
extern void Trackpad_Start_Poll(void);

/*****************************************************************************
* Function Name: Trackpad_Poll()
******************************************************************************
* Summary:
* This functions is used update baselines and decode gestures
*
* Parameters:
* None
*
* Return:
* None
*
* Theory:
* This function updates baseline value for all the sensors after scanning is complete and 
* decodes gesture based on number of fingers
*
* Side Effects:
* 
*
* NOTE:  Sequence of functions to be called by application for successful Trackpad Module scanning and 
*        gesture decoding is as follows
*        1) Trackpad_Start_Poll()
*        2) Trackpad_IsComplete()
*        3) Trackpad_Poll()
*****************************************************************************/
extern void Trackpad_Poll(void);

/*****************************************************************************
* Function Name: Trackpad_IsComplete()
******************************************************************************
* Summary:
* This functions is used return status of trackpad scanning
*
* Parameters:
* None
*
* Return:
* Returns status of trackpad scanning
*
* Theory:
* This function polls for the status of trackpad scanning and returns the scanning status information
*
* Side Effects:
* 
*
* NOTE:  Sequence of functions to be called by application for successful Trackpad Module scanning and 
*        gesture decoding is as follows
*        1) Trackpad_Start_Poll()
*        2) Trackpad_IsComplete()
*        3) Trackpad_Poll()
*****************************************************************************/
extern bool Trackpad_IsComplete(void);

/*****************************************************************************
* Function Name: Trackpad_Set_State()
******************************************************************************
* Summary:
* This function sets state of trackpad module
*                 
* Parameters:
* Device_State state - state of the trackpad module
*
* Return:
* None
*
* Theory:
* 
*
*
* Side Effects:
* 
*
*****************************************************************************/
extern void Trackpad_Set_State(Device_State state);

/*****************************************************************************
* Function Name: Trackpad_IsActive()
******************************************************************************
* Summary:
* This function returns user activity status on the trackpad
*                 
* Parameters:
* None
*
* Return:
* Returns status of trackpad activity
*
* Theory:
* 
*
*
* Side Effects:
* 
*
*****************************************************************************/
extern bool Trackpad_IsActive(void);

/*****************************************************************************
* Function Name: Trackpad_Stop()
******************************************************************************
* Summary:
* This function stops trackpad module scanning
*                 
* Parameters:
* None
*
* Return:
* None
*
* Theory:
* 
*
*
* Side Effects:
* 
*
*****************************************************************************/
extern void Trackpad_Stop(void);

/*****************************************************************************
* Function Name: Trackpad_Get_Report()
******************************************************************************
* Summary:
* This function generates report for touch containing the delta in x, y, zwheel, mkey and kcode
*                 
* Parameters:
* Report *report - Pointer for report structure
*
* Return:
* Returns Report type based on detected gesture
*
* Theory:
* Based on the trackpad event appropriate event is generated and  report for touch containing 
* delta in x, y, zwheel, mkey and kcode
*
*
* Side Effects:
* 
*
*****************************************************************************/
extern ReportType Trackpad_Get_Report(Report *report);

/*****************************************************************************
* Function Name: Trackpad_Reset()
******************************************************************************
* Summary:
* This function is reset the trackpad module
*
* Parameters:
* None
*
* Return:
* None
*
*****************************************************************************/
extern void Trackpad_Reset(void);
#else
#define Trackpad_Init()
#define Trackpad_Start_Poll()
#define Trackpad_Poll()
#define Trackpad_IsComplete()                               true
#define Trackpad_Set_State(state)
#define Trackpad_IsActive()                                 false
#define Trackpad_Stop()
#define Trackpad_Get_Report(report)                         NO_REPORT
#define Trackpad_Reset()
#endif /* DISABLE_TRACKPAD */

#endif /* _TRACKPAD_H_ */
